package com.x52im.rainbowchat.http.logic.pay.redenvelope;

import com.alibaba.fastjson.JSON;
import com.x52im.rainbowchat.http.dao.AlipayDAO;
import com.x52im.rainbowchat.http.dao.UserDAO;
import com.x52im.rainbowchat.http.logic.dto.AccountDTO;
import com.x52im.rainbowchat.http.logic.dto.RedEnvelopeDTO;

import java.util.List;
import java.util.Map;

/**
 * 查询账户
 */
public class MAccountQuery extends ARedEnvelope {
    @Override
    public String deal(RedEnvelopeDTO dto) throws Exception {
        UserDAO dao = new UserDAO();
        String isRealName = dao.queryUserRealName(dto.getUserUid());

        int total = moneyDAO.queryAccountTotal(dto.getUserUid());
        AccountDTO accountDTO = new AccountDTO();
        accountDTO.setTotal(String.valueOf(total));
        accountDTO.setIsRealname(isRealName);

        if (dto.getNeedAlipayList().equals("1")) {
            AlipayDAO alipayDAO = new AlipayDAO();
            List<Map<String, Object>> allList = alipayDAO.queryDepositListAndCashList(dto.getUserUid());
            accountDTO.setList(allList);
        }

        return JSON.toJSONString(accountDTO);
    }
}
